using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;

using PickGold.Charting.Utilities;
using PickGold.Charting.Design;

namespace PickGold.Charting
{
	[SRDescription("DescriptionAttributePolylineAnnotation_PolylineAnnotation"), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class PolylineAnnotation : Annotation
	{
		private System.Drawing.Drawing2D.GraphicsPath _defaultGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
		private LineAnchorCapStyle _endCap;
		private System.Drawing.Drawing2D.GraphicsPath _graphicsPath;
		private AnnotationPathPointCollection _pathPoints;
		private LineAnchorCapStyle _startCap;
		internal bool isFreeDrawPlacement;
		internal bool isPolygon;
		internal bool pathChanged;

		public PolylineAnnotation()
		{
			this._pathPoints = new AnnotationPathPointCollection(this);
			this._graphicsPath = this._defaultGraphicsPath;
		}

		internal override void AdjustLocationSize(SizeF movingDistance, ResizingMode resizeMode, bool pixelCoord, bool userInput)
		{
			if (resizeMode != ResizingMode.MovingPathPoints)
			{
				base.AdjustLocationSize(movingDistance, resizeMode, pixelCoord, userInput);
			}
			else
			{
				PointF empty = PointF.Empty;
				PointF anchorLocation = PointF.Empty;
				SizeF size = SizeF.Empty;
				this.GetRelativePosition(out empty, out size, out anchorLocation);
				if (userInput)
				{
					System.Drawing.Drawing2D.GraphicsPath startMovePathRel = base.startMovePathRel;
				}
				if (pixelCoord)
				{
					movingDistance = base.GetGraphics().GetRelativeSize(movingDistance);
				}
				movingDistance.Width /= this.startMovePositionRel.Width / 100f;
				movingDistance.Height /= this.startMovePositionRel.Height / 100f;
				if (this._graphicsPath.PointCount > 0)
				{
					System.Drawing.Drawing2D.GraphicsPath path = userInput ? base.startMovePathRel : this._graphicsPath;
					PointF[] pathPoints = path.PathPoints;
					byte[] pathTypes = path.PathTypes;
					for (int i = 0; i < pathPoints.Length; i++)
					{
						if (((base.currentPathPointIndex == i) || (base.currentPathPointIndex < 0)) || (base.currentPathPointIndex >= pathPoints.Length))
						{
							pathPoints[i].X -= movingDistance.Width;
							pathPoints[i].Y -= movingDistance.Height;
						}
					}
					this._defaultGraphicsPath.Dispose();
					this._defaultGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath(pathPoints, pathTypes);
					this._graphicsPath = this._defaultGraphicsPath;
					this.pathChanged = true;
					this.Invalidate();
				}
			}
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (this._defaultGraphicsPath != null)
				{
					this._defaultGraphicsPath.Dispose();
					this._defaultGraphicsPath = null;
				}
				if (this._pathPoints != null)
				{
					this._pathPoints.Dispose();
					this._pathPoints = null;
				}
			}
			base.Dispose(disposing);
		}

		internal override void Paint(Chart chart, ChartGraphics graphics)
		{
			if (this._graphicsPath.PointCount != 0)
			{
				PointF empty = PointF.Empty;
				PointF anchorLocation = PointF.Empty;
				SizeF size = SizeF.Empty;
				this.GetRelativePosition(out empty, out size, out anchorLocation);
				PointF tf3 = new PointF(empty.X + size.Width, empty.Y + size.Height);
				RectangleF ef2 = new RectangleF(empty, new SizeF(tf3.X - empty.X, tf3.Y - empty.Y));
				RectangleF rectangle = new RectangleF(ef2.Location, ef2.Size);
				if (rectangle.Width < 0f)
				{
					rectangle.X = rectangle.Right;
					rectangle.Width = -rectangle.Width;
				}
				if (rectangle.Height < 0f)
				{
					rectangle.Y = rectangle.Bottom;
					rectangle.Height = -rectangle.Height;
				}
				if ((!float.IsNaN(rectangle.X) && !float.IsNaN(rectangle.Y)) && (!float.IsNaN(rectangle.Right) && !float.IsNaN(rectangle.Bottom)))
				{
					RectangleF absoluteRectangle = graphics.GetAbsoluteRectangle(rectangle);
					float num = absoluteRectangle.Width / 100f;
					float num2 = absoluteRectangle.Height / 100f;
					PointF[] pathPoints = this._graphicsPath.PathPoints;
					byte[] pathTypes = this._graphicsPath.PathTypes;
					for (int i = 0; i < pathPoints.Length; i++)
					{
						pathPoints[i].X = absoluteRectangle.X + (pathPoints[i].X * num);
						pathPoints[i].Y = absoluteRectangle.Y + (pathPoints[i].Y * num2);
					}
					using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(pathPoints, pathTypes))
					{
						bool flag = false;
						LineCap flat = LineCap.Flat;
						LineCap endCap = LineCap.Flat;
						if (!this.isPolygon && ((this._startCap != LineAnchorCapStyle.None) || (this._endCap != LineAnchorCapStyle.None)))
						{
							flag = true;
							flat = graphics.Pen.StartCap;
							endCap = graphics.Pen.EndCap;
							if (this._startCap == LineAnchorCapStyle.Arrow)
							{
								if (this.LineWidth < 4)
								{
									int num4 = 3 - this.LineWidth;
									graphics.Pen.StartCap = LineCap.Custom;
									graphics.Pen.CustomStartCap = new AdjustableArrowCap((float)(this.LineWidth + num4), (float)(this.LineWidth + num4), true);
								}
								else
								{
									graphics.Pen.StartCap = LineCap.ArrowAnchor;
								}
							}
							else if (this._startCap == LineAnchorCapStyle.Diamond)
							{
								graphics.Pen.StartCap = LineCap.DiamondAnchor;
							}
							else if (this._startCap == LineAnchorCapStyle.Round)
							{
								graphics.Pen.StartCap = LineCap.RoundAnchor;
							}
							else if (this._startCap == LineAnchorCapStyle.Square)
							{
								graphics.Pen.StartCap = LineCap.SquareAnchor;
							}
							if (this._endCap == LineAnchorCapStyle.Arrow)
							{
								if (this.LineWidth < 4)
								{
									int num5 = 3 - this.LineWidth;
									graphics.Pen.EndCap = LineCap.Custom;
									graphics.Pen.CustomEndCap = new AdjustableArrowCap((float)(this.LineWidth + num5), (float)(this.LineWidth + num5), true);
								}
								else
								{
									graphics.Pen.EndCap = LineCap.ArrowAnchor;
								}
							}
							else if (this._endCap == LineAnchorCapStyle.Diamond)
							{
								graphics.Pen.EndCap = LineCap.DiamondAnchor;
							}
							else if (this._endCap == LineAnchorCapStyle.Round)
							{
								graphics.Pen.EndCap = LineCap.RoundAnchor;
							}
							else if (this._endCap == LineAnchorCapStyle.Square)
							{
								graphics.Pen.EndCap = LineCap.SquareAnchor;
							}
						}
						if (base.Common.ProcessModePaint)
						{
							if (this.isPolygon)
							{
								path.CloseAllFigures();
								graphics.DrawPathAbs(path, this.BackColor, this.BackHatchStyle, string.Empty, ChartImageWrapMode.Scaled, Color.Empty, ChartImageAlignmentStyle.Center, this.BackGradientStyle, this.BackSecondaryColor, this.LineColor, this.LineWidth, this.LineDashStyle, PenAlignment.Center, this.ShadowOffset, this.ShadowColor);
							}
							else
							{
								graphics.DrawPathAbs(path, Color.Transparent, ChartHatchStyle.None, string.Empty, ChartImageWrapMode.Scaled, Color.Empty, ChartImageAlignmentStyle.Center, GradientStyle.None, Color.Empty, this.LineColor, this.LineWidth, this.LineDashStyle, PenAlignment.Center, this.ShadowOffset, this.ShadowColor);
							}
						}
						if (base.Common.ProcessModeRegions)
						{
							System.Drawing.Drawing2D.GraphicsPath path2 = null;
							System.Drawing.Drawing2D.GraphicsPath path3 = null;
							if (this.isPolygon)
							{
								path2 = path;
							}
							else
							{
								path3 = new System.Drawing.Drawing2D.GraphicsPath();
								path2 = path3;
								path2.AddPath(path, false);
								using (Pen pen = (Pen)graphics.Pen.Clone())
								{
									pen.DashStyle = DashStyle.Solid;
									pen.Width += 2f;
									try
									{
										path2.Widen(pen);
									}
									catch (OutOfMemoryException)
									{
									}
									catch (ArgumentException)
									{
									}
								}
							}
							base.Common.HotRegionsList.AddHotRegion(graphics, path2, false, base.ReplaceKeywords(this.ToolTip), base.ReplaceKeywords(this.Url), base.ReplaceKeywords(this.MapAreaAttributes), base.ReplaceKeywords(base.PostBackValue), this, ChartElementType.Annotation);
							if (path3 != null)
							{
								path3.Dispose();
							}
						}
						if (flag)
						{
							graphics.Pen.StartCap = flat;
							graphics.Pen.EndCap = endCap;
						}
						this.PaintSelectionHandles(graphics, rectangle, path);
					}
				}
			}
		}

		[DefaultValue(typeof(ContentAlignment), "MiddleCenter"), Browsable(false), SRCategory("CategoryAttributeAppearance")]
		public override ContentAlignment Alignment
		{
			get
			{
				return base.Alignment;
			}
			set
			{
				base.Alignment = value;
			}
		}

		[Bindable(true), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SerializationVisibility(SerializationVisibility.Hidden), SRDescription("DescriptionAttributeAnnotationType"), Browsable(false), SRCategory("CategoryAttributeMisc")]
		public override string AnnotationType
		{
			get
			{
				return "Polyline";
			}
		}

		[Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), NotifyParentProperty(true), TypeConverter(typeof(ColorConverter)), SRCategory("CategoryAttributeAppearance"), Browsable(false), DefaultValue(typeof(Color), "")]
		public override Color BackColor
		{
			get
			{
				return base.BackColor;
			}
			set
			{
				base.BackColor = value;
			}
		}

		[Editor(typeof(GradientEditor), typeof(UITypeEditor)), NotifyParentProperty(true), SRCategory("CategoryAttributeAppearance"), Browsable(false), DefaultValue(0)]
		public override GradientStyle BackGradientStyle
		{
			get
			{
				return base.BackGradientStyle;
			}
			set
			{
				base.BackGradientStyle = value;
			}
		}

		[Editor(typeof(HatchStyleEditor), typeof(UITypeEditor)), NotifyParentProperty(true), SRCategory("CategoryAttributeAppearance"), Browsable(false), DefaultValue(0)]
		public override ChartHatchStyle BackHatchStyle
		{
			get
			{
				return base.BackHatchStyle;
			}
			set
			{
				base.BackHatchStyle = value;
			}
		}

		[Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), SRCategory("CategoryAttributeAppearance"), Browsable(false), DefaultValue(typeof(Color), ""), NotifyParentProperty(true), TypeConverter(typeof(ColorConverter))]
		public override Color BackSecondaryColor
		{
			get
			{
				return base.BackSecondaryColor;
			}
			set
			{
				base.BackSecondaryColor = value;
			}
		}

		[SRCategory("CategoryAttributeAppearance"), DefaultValue(0), SRDescription("DescriptionAttributeStartCap3")]
		public virtual LineAnchorCapStyle EndCap
		{
			get
			{
				return this._endCap;
			}
			set
			{
				this._endCap = value;
				this.Invalidate();
			}
		}

		[DefaultValue(typeof(System.Drawing.Font), "Microsoft Sans Serif, 8pt"), Browsable(false), SRCategory("CategoryAttributeAppearance")]
		public override System.Drawing.Font Font
		{
			get
			{
				return base.Font;
			}
			set
			{
				base.Font = value;
			}
		}

		[SRCategory("CategoryAttributeAppearance"), TypeConverter(typeof(ColorConverter)), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), Browsable(false), DefaultValue(typeof(Color), "Black"), SRDescription("DescriptionAttributeForeColor")]
		public override Color ForeColor
		{
			get
			{
				return base.ForeColor;
			}
			set
			{
				base.ForeColor = value;
			}
		}

		[SRCategory("CategoryAttributePosition"), DefaultValue((string)null), SRDescription("DescriptionAttributePath"), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SerializationVisibility(SerializationVisibility.Hidden)]
		public virtual System.Drawing.Drawing2D.GraphicsPath GraphicsPath
		{
			get
			{
				return this._graphicsPath;
			}
			set
			{
				this._graphicsPath = value;
				this.pathChanged = true;
			}
		}

		[SRCategory("CategoryAttributePosition"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), EditorBrowsable(EditorBrowsableState.Never), Editor(typeof(ChartCollectionEditor), typeof(UITypeEditor)), SRDescription("DescriptionAttributePathPoints"), PersistenceMode(PersistenceMode.InnerProperty)]
		public AnnotationPathPointCollection GraphicsPathPoints
		{
			get
			{
				if (this.pathChanged || (this._graphicsPath.PointCount != this._pathPoints.Count))
				{
					this._pathPoints.annotation = null;
					this._pathPoints.Clear();
					if (this._graphicsPath.PointCount > 0)
					{
						PointF[] pathPoints = this._graphicsPath.PathPoints;
						byte[] pathTypes = this._graphicsPath.PathTypes;
						for (int i = 0; i < pathPoints.Length; i++)
						{
							this._pathPoints.Add(new AnnotationPathPoint(pathPoints[i].X, pathPoints[i].Y, pathTypes[i]));
						}
					}
					this._pathPoints.annotation = this;
				}
				return this._pathPoints;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Never), DefaultValue(false), SRDescription("DescriptionAttributeFreeDrawPlacement"), Browsable(false), SRCategory("CategoryAttributeMisc")]
		public virtual bool IsFreeDrawPlacement
		{
			get
			{
				return this.isFreeDrawPlacement;
			}
			set
			{
				this.isFreeDrawPlacement = value;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Never), DefaultValue(1), ParenthesizePropertyName(true), Browsable(false), SRCategory("CategoryAttributeAppearance"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SerializationVisibility(SerializationVisibility.Hidden), SRDescription("DescriptionAttributeSelectionPointsStyle")]
		internal override SelectionPointsStyle SelectionPointsStyle
		{
			get
			{
				return SelectionPointsStyle.Rectangle;
			}
		}

		[SRDescription("DescriptionAttributeStartCap3"), SRCategory("CategoryAttributeAppearance"), DefaultValue(0)]
		public virtual LineAnchorCapStyle StartCap
		{
			get
			{
				return this._startCap;
			}
			set
			{
				this._startCap = value;
				this.Invalidate();
			}
		}

		[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
		public override TextStyle TextStyle
		{
			get
			{
				return base.TextStyle;
			}
			set
			{
				base.TextStyle = value;
			}
		}
	}
}

